package com.ruoyi.logistic.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkPackageWeightDifference;
import com.ruoyi.logistic.domain.NetworkPackageWeightDifferenceCollect;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.Quotation;
import com.ruoyi.logistic.domain.vo.NetworkPackageWeightDifferenceCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkPackageWeightDifferenceVo;
import com.ruoyi.logistic.domain.vo.QuotationVo;
import com.ruoyi.logistic.service.NetworkPackageWeightDifferenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/network/PackageWeight")
@RestController
@Api(tags = "网点财务_包重差异报表")
public class NetworkPackageWeightDifferenceController {
    @Autowired
    private NetworkPackageWeightDifferenceService networkPackageWeightDifferenceService;

    @ApiOperation("明细")
    @PostMapping("/search")
    public R search(@RequestBody NetworkPackageWeightDifferenceVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null) {
            return R.ok("请传入所需的时间参数！");
        }
        List<NetworkPackageWeightDifference> list = networkPackageWeightDifferenceService.search(vo);
        if (list == null || list.size() == 0) {
            return R.ok("暂无数据");
        } else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list", PageInfo.info(list));
            jsonObject.put("fields", networkPackageWeightDifferenceService.initTable());
            return R.ok(jsonObject);
        }
    }

    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R search(@RequestBody NetworkPackageWeightDifferenceCollectVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null) {
            return R.ok("请传入所需的时间参数！");
        }
        List<NetworkPackageWeightDifferenceCollect> list = networkPackageWeightDifferenceService.collect(vo);
        if (list == null || list.size() == 0) {
            return R.ok("暂无数据");
        } else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list", PageInfo.info(list));
            jsonObject.put("fields", networkPackageWeightDifferenceService.initCollectTable());
            return R.ok(jsonObject);
        }
    }
}